<%@ page language="java" contentType="text/html;charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ page import="com.jack.bookshop.vo.BookVo" %>
<%@ page import="com.jack.bookshop.dao.BookDao" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>

<%
    String idStr = request.getParameter("id");
    if (idStr != null) {
        int id = 0;
        try {
            id = Integer.parseInt(idStr);
            BookVo book = new BookDao().getOneById(id);
            pageContext.setAttribute("book", book);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
%>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Justin's Bookshop</title>
    <!-- 导入资源 -->
    <%@ include file="resource.jsp" %>
</head>
<body>
<!-- 导入页头 -->
<%@ include file="header.jsp" %>
<div class="container" style="margin: 24px auto;">
    <div class="row">
        <div id="main" class="col-md-9">
            <p>
                <a href="index.jsp">Home</a> >>
                <a href="category.jsp">Category</a> >>
                <a href="category.jsp">${book.c1_text}</a> >>
                <a href="book.jsp?c2=${book.c2_id}&page=1&size=2">${book.c2_text}</a> >>
                <a href="book-one.jsp?id=${book.id}">${book.title}</a>
            </p>
            <h2 class="text-center">Book View</h2>
            <hr/>
            <h3 class="text-center">${pageScope.book.title}</h3>
            <p>
                <img src="assets/images/books/${book.image_url}"
                     class="img-responsive text-center"/>
            </p>
            <p>
                <strong>Category:</strong> <a href="#">${book.c1_text}</a> >> <a
                    href="#">${book.c2_text}</a>
            </p>
            <p>
                <strong>Score:</strong>
                <c:forEach begin="1" end="${book.score}" var="i">
                    <i class="bi bi-star-fill"></i>
                </c:forEach>
                <%--        <c:forEach begin="1" end="${book.score}" var="i">--%>
                <%--						<span class="glyphicon glyphicon-star" style="color: orange;"--%>
                <%--                              aria-hidden="true"></span>--%>

                <%--        </c:forEach>--%>
            </p>
            <p>
                <strong>Price:</strong> $${book.price}
            </p>
            <p>
                <a href="cart.do?action=add&bookId=${book.id}"
                   class="btn btn-primary">Add to Shopping Cart</a>
            </p>
            <p>
                <strong>Description:</strong> ${book.description}
            </p>

        </div>
        <div id="side" class="col-md-3">
            <!-- 导入侧边栏 -->
            <%@ include file="sider.jsp" %>
        </div>
        <div class="clear"></div>
    </div>
</div>
<!-- 导入页脚 -->
<%@ include file="footer.jsp" %>
</body>
</html>